﻿using IOA.MES.Client.Common;
using System.Windows;

namespace IOA.MES.Client.EL2
{
    /// <summary>
    /// WinElSettings.xaml 的交互逻辑
    /// </summary>
    public partial class WinElSettings : Window
    {
        public WinElSettings()
        {
            InitializeComponent();

            var httpRoot = BaseEnv.GetStorage("El2HttpRoot");
            if (string.IsNullOrWhiteSpace(httpRoot))
            {
                httpRoot = "http://127.0.0.1:1000/";
                BaseEnv.SetStorage("El2HttpRoot", httpRoot);
            }
            txtAddress.Text = httpRoot;
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            var httpRoot = txtAddress.Text.Trim();
            if (string.IsNullOrWhiteSpace(httpRoot))
            {
                MessageBox.Show("请填写合法的Http监听地址");
                return;
            }
            else if (!httpRoot.EndsWith("/"))
            {
                MessageBox.Show("Http监听地址必须以“/”结尾");
                return;
            }
            BaseEnv.SetStorage("El2HttpRoot", httpRoot);
            this.DialogResult = true;
            this.Close();
        }
    }
}
